#include<stdio.h>

int main() {
    int T;
    while (scanf("%d", &T) != EOF) {
        while (T--) {
            int n;
            int x, y, z;
            scanf("%d %d %d %d", &n, &x, &y, &z);
            int sum = (x + 2 * y + 3 * z) / 7;
            if (x + y + z == n && (x + 2 * y + 3 * z) % 7 == 0)
                printf("%d\n", sum);
        }
    }
    return 0;
}